package model

import (
	"gitee.com/csingo/cDB"
	"github.com/gin-gonic/gin"
	"time"
)

type Includes struct {
	ID        uint64     `gorm:"column:id" json:"id"`
	Name      string     `gorm:"column:name" json:"name"`
	CreatedAt *time.Time `gorm:"column:created_at;<-:create" json:"created_at"`
	UpdatedAt *time.Time `gorm:"column:updated_at" json:"updated_at"`
}

func (i *Includes) Connection() string {
	return "default"
}

func (i *Includes) Add(ctx *gin.Context, name string) (*Includes, error) {
	data := &Includes{Name: name}
	err := cDB.Query(data).Create(data).Error
	return data, err
}

func (i *Includes) DelById(ctx *gin.Context, id uint64) error {
	err := cDB.Query(i).Delete(&Includes{ID: id}).Error
	return err
}

func (i *Includes) All(ctx *gin.Context) ([]*Includes, error) {
	res := []*Includes{}
	err := cDB.Query(i).Find(&res).Error
	return res, err
}
